ESE 124 Lecture Notes - Lecture 2: Initial Condition

55 views4 pages

Document Summary

How to do looping: method 1: using the while statement. Illustrate the usage of the while statement by designing a program which, when run, will print hello five times. While looping requires initialization of looping index i int i=1; // declaration & initialization of looping index i. While looping requires specifying the final value of i while(i<=5){ printf( hello\n ); i=i+1; While looping requires this increment condition return 0; In using the while looping command, one requires the specification of 3 things: i) Initialization of looping index i before looping starts ii) Final value of i specified in the argument of the while statement iii) Increment condition on i within the while looping segment. Repeat the above program but now using the for command. #include int main(){ int i; // declaration of looping index i for(i=1;i<=5;i=i+1){ printf( hello\n ); return 0; Note: both the while and for looping methods require the specification of the same three things: i) ii) iii)

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents