×

# Looping and control structure

 0 #include int main() { int i=3; while(i--) { int i=100; i--; print("%d",i); } return 0; }  My output was coming infinite as 99 will repeat again and again but the answer was just 3 99s i.e. 99 99 99. How?! asked 14 Aug '18, 13:29 1 accept rate: 0%

 0 It is because variable i declared inside and outside of while loop are different variables with different scopes. Variable i declared outside of the the loop is used as counter variable for the loop(it keeps on decrementing until it becomes 0), while one declared inside the loop is used for printing(it is redeclared and reassigned to 100 everytime loop runs). answered 14 Aug '18, 15:21 1●1 accept rate: 0%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,491
×966
×191
×139
×135

question asked: 14 Aug '18, 13:29

question was seen: 158 times

last updated: 14 Aug '18, 13:29