The Artima Developer Community
Sponsored Link

Java Answers Forum
New to java, how to do a certain loop

2 replies on 1 page. Most recent reply: Sep 22, 2005 11:40 PM by Kondwani Mkandawire

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Jon

Posts: 1
Nickname: clarjon1
Registered: Sep, 2005

New to java, how to do a certain loop Posted: Sep 22, 2005 10:18 AM
Reply to this message Reply
Advertisement
OK, I am new to Java, and I used to use Turing. In turing, there is this one loop where it would loop until a variable number was met or passed. Anything like that in Java? Thanks!


Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: New to java, how to do a certain loop Posted: Sep 22, 2005 11:22 PM
Reply to this message Reply
1. Checks the condition before the loop (makes it possible that the loop will never be executed) Needs external variables for the ondition.
    while ([condition]) {
        //do something very important
    }


2. Checks the condition after the loop (the loop will be executed at leas once). Needs external variables for the ondition.
    {
        //do something very important
    } while ([condition]);


3. Classic for-to statement. Allows to declare a condition variable only for this loop, not visible outside the loop
    for ([declare and initialize variable]; [condition]; [operation after each loop]) {
        //do something very important
    }
//for example:
    for (int i = 0; i < 50; i++) {
        //do something very important
    }


[condition] : means, that you can evaluate your variable here, for example: i < 50
As long this evaluation returns true, the loop will be executed.

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: New to java, how to do a certain loop Posted: Sep 22, 2005 11:40 PM
Reply to this message Reply
> OK, I am new to Java, and I used to use Turing. In
> turing, there is this one loop where it would loop until a
> variable number was met or passed. Anything like that in
> Java? Thanks!

If I remember my one of my CS courses correctly,
anything done at the hardware level, can be simulted
at the software level. So anything a Turing machine
can (theoretically) be proven to do, would have its
Java equivalent

Flat View: This topic has 2 replies on 1 page
Topic: finally clause not executed Previous Topic   Next Topic Topic: how to run jcifs programs

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use