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/rest-api/class-wp-rest-server.php on line 1831

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/rest-api/class-wp-rest-server.php on line 1831

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/rest-api/class-wp-rest-server.php on line 1831

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/rest-api/class-wp-rest-server.php on line 1831

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/rest-api/class-wp-rest-server.php on line 1831

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/rest-api/class-wp-rest-server.php on line 1831

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/rest-api/class-wp-rest-server.php on line 1831

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/rest-api/class-wp-rest-server.php on line 1831
{"id":25546,"date":"2015-10-30T20:02:56","date_gmt":"2015-10-31T02:02:56","guid":{"rendered":"http:\/\/myfreakingcrazythoughts.wordpress.com\/?p=155"},"modified":"2015-10-30T20:02:56","modified_gmt":"2015-10-31T02:02:56","slug":"using-loops-for-and-while","status":"publish","type":"post","link":"https:\/\/kenscourses.com\/tc101fall2015\/2015\/using-loops-for-and-while\/","title":{"rendered":"Using Loops FOR and WHILE"},"content":{"rendered":"

Loops <\/strong><\/p>\n

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.<\/p>\n

FOR<\/strong> – for loops are the most useful type. The syntax for a for loop is:<\/p>\n

\n
For<\/span> (variable<\/span> initialization;<\/span> condition;<\/span> variable<\/span> update)<\/span> {<\/span>\n  Code<\/span> to<\/span> execute<\/span> while<\/span> the<\/span> condition<\/span> is<\/span> true<\/span>\n}<\/span>\n<\/pre>\n<\/div>\n

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.<\/p>\n

\u00a0<\/strong><\/p>\n

WHILE – <\/strong>WHILE loops are very simple. The basic structure is<\/p>\n

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.<\/p>\n

Example:<\/p>\n

\n
#include <iostream><\/span>\n\nUsing<\/span> namespace<\/span> std;<\/span> \/\/ So we can see cout and endl<\/span>\n\nint<\/span> main<\/span>()<\/span>\n{<\/span> \n  int<\/span> x<\/span> =<\/span> 0<\/span>;<\/span>  \/\/ Don't forget to declare variables<\/span>\n  \n  while<\/span> (<\/span> x<\/span> <<\/span> 10<\/span> )<\/span> {<\/span> \/\/ While x is less than 10 <\/span>\n    cout<<<\/span> x<\/span> <<endl;<\/span>\n    x++;<\/span>             \/\/ Update x so the condition can be met eventually<\/span>\n  }<\/span>\n  cin.get();<\/span>\n}<\/span>\n<\/pre>\n<\/div>\n

Here is an example of a program which has loops (factorial calculator<\/a>):<\/p>\n

\n
\/* Source code to find factorial of a number. *\/<\/span>\n#include <iostream><\/span>\nusing<\/span> namespace<\/span> std;<\/span>\nint<\/span> main<\/span>()<\/span>\n{<\/span>\n  int<\/span> x<\/span> ,<\/span> factorial=<\/span>1<\/span>;<\/span>\n\n    cout<\/span> <<<\/span> \"Please enter a non-negative number:  \"<\/span> <<<\/span> endl;<\/span>\n    cin<\/span> >><\/span> x;<\/span>\n\n    for<\/span>(<\/span>int<\/span> a=<\/span>1<\/span>;<\/span> a<=x;<\/span> a++)<\/span>\/\/HERE IS THE \"FOR\" LOOP<\/span>\n    {<\/span>\n        factorial=factorial*a;<\/span>\n    }<\/span>\n\ncout<\/span> <<<\/span> \"The factorial of your number is \"<\/span> <<<\/span> factorial<\/span> <<<\/span> endl;<\/span>\ncout<\/span> <<<\/span> \"Would you like to play again?   \"<\/span>;<\/span>\nstring<\/span> answer;<\/span>\ncin<\/span> >><\/span> answer;<\/span>\n\ndo<\/span>\n{<\/span>\n    int<\/span> x<\/span> ,<\/span> factorial=<\/span>1<\/span>;<\/span>\n\n    cout<\/span> <<<\/span> \"Please enter a non-negative number:  \"<\/span> <<<\/span> endl;<\/span>\n    cin<\/span> >><\/span> x;<\/span>\n\n    for<\/span>(<\/span>int<\/span> a=<\/span>1<\/span>;a<=x;a++)<\/span>\/\/HERE IS THE \"FOR\" LOOP<\/span>\n    {<\/span>\n        factorial=factorial*a;<\/span>\n    }<\/span>\n\n    cout<\/span> <<<\/span> \"The factorial of your number is \"<\/span> <<<\/span> factorial<\/span> <<<\/span> endl;<\/span>\n    cout<\/span> <<<\/span> \"Would you like to play again  ? \"<\/span>;<\/span>\n    cin<\/span> >><\/span> answer;<\/span>\n\n}<\/span>while<\/span> (answer<\/span> ==<\/span>\"yes\"<\/span>);<\/span>\/\/HERE IS THE \"WHILE\" LOOP<\/span>\n\nif<\/span> (answer==<\/span> \"no\"<\/span>)<\/span>\n{<\/span>\n  cout<\/span> <<<\/span> \"AS YOU WISH MASTER, MAY THE FORCE BE WITH YOU! \"<\/span> <<<\/span> endl;<\/span>\n}<\/span>\n\nreturn<\/span> 0<\/span>;<\/span>\n}<\/span>\n<\/pre>\n<\/div>\n

Thank’s to\u00a0http:\/\/www.cprogramming.com\/<\/a>\u00a0for the support!<\/p>\n

-The Admin.<\/p>\n

\"\"<\/a> \"\"<\/p>\n","protected":false},"excerpt":{"rendered":"

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… Continue Reading →<\/a>\"\"<\/p>\n","protected":false},"author":259,"featured_media":25545,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,3],"tags":[582,197,206,734,62,802,803,152,615],"_links":{"self":[{"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/posts\/25546"}],"collection":[{"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/users\/259"}],"replies":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/comments?post=25546"}],"version-history":[{"count":1,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/posts\/25546\/revisions"}],"predecessor-version":[{"id":25547,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/posts\/25546\/revisions\/25547"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/media\/25545"}],"wp:attachment":[{"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/media?parent=25546"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/categories?post=25546"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/tags?post=25546"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}