0
can anyone discuss it to me in a simple way
3 Answers
+ 1
can you show me the programme?
+ 1
First num is assigned the value 1.
The while loop checks to see if num is less than 6. If the condition is met, it runs. If not, it skips past the while loop. The first time, num = 1 so the loop executes.
In the loop, cout is a command to print output to the screen. "number" is a string it prints, then the variable num, then endl which is a return AKA line break. Finally, the value of num is increased by 3. So num now equals 4. Then the while loops checks to see if it should run again. Since 4 < 6, it will execute again the same way, but this time at the end num will be increased to 7. So when the loop checks num < 6 again, it will be checking 7 < 6. Since this is not true, the while loop does not execute and the program is complete.
The output will look something like:
number = 1
number = 4
0
int num=1
while (num<6) {
cout << "number" << num <<endl;
num=num+3 ;
}
it maybe seems easy but i am just a beginner đ