5 Replies - 362 Views - Last Post: 04 August 2014 - 03:05 AM Rate Topic: -----

#1 Eddieteo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-July 14

EMERGENCY! Need help about while loop!

Posted 03 August 2014 - 06:09 PM

[code]while (input == 'y')
{

main();
break;
}
[code/]

What does this mean? I dun understand why have to put the break, if i dun put the break and i put other alphabet or number, the loop will still run. But i thought only when I enter the input "y" , then only the loop will run??

But when i delete the break and i put other alphabet, the loop still keep going..
Please tell me why, its emergency!

Is This A Good Question/Topic? 0
  • +

Replies To: EMERGENCY! Need help about while loop!

#2 tarmizi_adam2005  Icon User is offline

  • جوروترا

Reputation: 244
  • View blog
  • Posts: 884
  • Joined: 18-April 09

Re: EMERGENCY! Need help about while loop!

Posted 03 August 2014 - 06:29 PM

Hi,

Well the break statement just "breaks" out of the loop. Have you tried reading this ?
Was This Post Helpful? 0
  • +
  • -

#3 Eddieteo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-July 14

Re: EMERGENCY! Need help about while loop!

Posted 03 August 2014 - 06:38 PM

Sorry, Im newbie, what i mean is when i type in 'y', the loop will continue, when i type other alphabet, the loop will break.

When i input the 'y', the loop goes to the main().

When i input other numbers or alphabets, the loop break.

but how?

i thought if the input is not y, the system will just skip the while loop?
Was This Post Helpful? 0
  • +
  • -

#4 tarmizi_adam2005  Icon User is offline

  • جوروترا

Reputation: 244
  • View blog
  • Posts: 884
  • Joined: 18-April 09

Re: EMERGENCY! Need help about while loop!

Posted 03 August 2014 - 06:44 PM

Quote

When i input the 'y', the loop goes to the main().


Yes, when you input 'y' the loop goes to main(). because of the condition

while(input =='y')


Quote

When i input other numbers or alphabets, the loop break.


When you input other number, or alphabets the loop is not executed. The program does not enter the loop and just goes to whatever code after the while loop.

You should never call your main() function. This is a really bad practice.

This post has been edited by tarmizi_adam2005: 03 August 2014 - 06:45 PM

Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3741
  • View blog
  • Posts: 13,086
  • Joined: 12-December 12

Re: EMERGENCY! Need help about while loop!

Posted 03 August 2014 - 10:19 PM

So where's the EMERGENCY?!
Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6092
  • View blog
  • Posts: 23,612
  • Joined: 23-August 08

Re: EMERGENCY! Need help about while loop!

Posted 04 August 2014 - 03:05 AM

Came expecting Randolph Mantooth, leaving disappointed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1