Warning: The magic method Slickr_Flickr_Plugin::__wakeup() must have public visibility in /home/kenbauer/public_kenscourses/tc101fall2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php on line 152

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101fall2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101fall2015/wp-includes/feed-rss2.php on line 8
‘#loops’ Articles at TC101 Fall 2015 https://kenscourses.com/tc101fall2015 Introduction to Programming Python and C++ Wed, 25 Nov 2015 04:04:59 +0000 en hourly 1 https://creativecommons.org/licenses/by/4.0/ Matery 22 https://kenscourses.com/tc101fall2015/2015/matery-22/ Wed, 25 Nov 2015 04:04:59 +0000 http://opezaimd.tumblr.com/post/133906465560 On this mastery I’ll show you when to use what type of repetition in a program. 

For the purpose of this mastery, we’ll focus on while and for loops because they are the easiest and most used ones.

On mastery 19 we learned how to use a while loop. The while loop consists of something that will happen WHILE a condition is given. For example: WHILE x is greater or equal than 0, something will happen, and this process will continue to happen WHILE this condition is true.

On mastery 20 we learned how to use a for loop. A FOR loop is a type of loop which allows you to give specific conditions to it, and then repeat when this conditions are true.

Now, while and for may be seem like they are the same, but they certainly ain’t. The main difference between them is that FOR loops will continue happening for a given number of iterations. 

As you may recall, functions often use a for loop because of the iteration part. In someway, FOR loops are “better” when dealing with functions, while WHILE loops are great to work with inside main().

Picture and more information from this webpage.

]]>
On this mastery I’ll show you when to use what type of repetition in a program. 

For the purpose of this mastery, we’ll focus on while and for loops because they are the easiest and most used ones.

On mastery 19 we learned how to use a while loop. The while loop consists of something that will happen WHILE a condition is given. For example: WHILE x is greater or equal than 0, something will happen, and this process will continue to happen WHILE this condition is true.

On mastery 20 we learned how to use a for loop.

A FOR loop is a type of loop which allows you to give specific conditions to it, and then repeat when this conditions are true.

Now, while and for may be seem like they are the same, but they certainly ain’t. The main difference between them is that FOR loops will continue happening for a given number of iterations. 

As you may recall, functions often use a for loop because of the iteration part. In someway, FOR loops are “better” when dealing with functions, while WHILE loops are great to work with inside main().

Picture and more information from this webpage.

]]>
https://creativecommons.org/licenses/by/4.0/
Using Loops FOR and WHILE https://kenscourses.com/tc101fall2015/2015/using-loops-for-and-while/ Sat, 31 Oct 2015 02:02:56 +0000 http://myfreakingcrazythoughts.wordpress.com/?p=155 Continue Reading →]]> Loops

Loops are used to repeat a block of code. Being able to have your program repeatedly execute a block of code is one of the most basic but useful tasks in programming — many programs or websites that produce extremely complex output (such as a message board) are really only executing a single task many times.

FOR – for loops are the most useful type. The syntax for a for loop is:

For (variable initialization; condition; variable update) {
  Code to execute while the condition is true
}

The variable initialization allows you to either declare a variable and give it a value or give a value to an already existing variable. Second, the condition tells the program that while the conditional expression is true the loop should continue to repeat itself.

 

WHILE – WHILE loops are very simple. The basic structure is

while (condition) {Code to execute while the condition is true} the true represents a Boolean expression. It can be any combination of Boolean statements that are legal.) Notice that a while loop is the same as a for loop without the initialization and update sections. However, an empty condition is not legal for a while loop as it is with a for loop.

Example:

#include <iostream>

Using namespace std; // So we can see cout and endl

int main()
{ 
  int x = 0;  // Don't forget to declare variables
  
  while ( x < 10 ) { // While x is less than 10 
    cout<< x <<endl;
    x++;             // Update x so the condition can be met eventually
  }
  cin.get();
}

Here is an example of a program which has loops (factorial calculator):

/* Source code to find factorial of a number. */
#include <iostream>
using namespace std;
int main()
{
  int x , factorial=1;

    cout << "Please enter a non-negative number:  " << endl;
    cin >> x;

    for(int a=1; a<=x; a++)//HERE IS THE "FOR" LOOP
    {
        factorial=factorial*a;
    }

cout << "The factorial of your number is " << factorial << endl;
cout << "Would you like to play again?   ";
string answer;
cin >> answer;

do
{
    int x , factorial=1;

    cout << "Please enter a non-negative number:  " << endl;
    cin >> x;

    for(int a=1;a<=x;a++)//HERE IS THE "FOR" LOOP
    {
        factorial=factorial*a;
    }

    cout << "The factorial of your number is " << factorial << endl;
    cout << "Would you like to play again  ? ";
    cin >> answer;

}while (answer =="yes");//HERE IS THE "WHILE" LOOP

if (answer== "no")
{
  cout << "AS YOU WISH MASTER, MAY THE FORCE BE WITH YOU! " << endl;
}

return 0;
}

Thank’s to http://www.cprogramming.com/ for the support!

-The Admin.

]]>
https://creativecommons.org/licenses/by/4.0/
Mastery 19 – Use of loops with While https://kenscourses.com/tc101fall2015/2015/mastery-19-use-of-loops-with-while-2/ Tue, 15 Sep 2015 14:04:00 +0000 http://kenscourses.com/tc101fall2015/?guid=63efebad0f04a53177e6e2f862caf99c I know how to use loops, its really simple. I will show you a WHILE loop that I used in the WSQ07:

This loop makes posible the constant repetition of one statement, it can also work with variables and numbers thats why I put the counter inside. The WHILE loop does not need parenthesis like the IF.

]]>
https://creativecommons.org/licenses/by/4.0/