• Post Reply Bookmark Topic Watch Topic
  • New Topic

UserInput  RSS feed

 
ekte spiriopoulos
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use userinput.getString() the method you know.
I want if user write Back to stop .Will work or not ? I did this : this is good or false?
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry, that code snippet is difficult to understand. Most likely it is incorrect in any context.
Could you please explain in couple of sentences what do you want to do without using any Java language words as (String, while, Integer and similar).
 
ekte spiriopoulos
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liutauras Vilda wrote:I'm sorry, that code snippet is difficult to understand. Most likely it is incorrect in any context.
Could you please explain in couple of sentences what do you want to do without using any Java language words as (String, while, Integer and similar).

I want to press or write the button Escape (or to write it the Escape) and to go back at the begging of my code .While(Escape!= x) repeat.When it goes x=Escape to finish the while .Escape should be string
 
Fred Kleinschmidt
Bartender
Posts: 571
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

No, this is not correct.
First, why are "x" and "code" declared as static?
Second, you have a undefined symbol named Back.
What I think you want is

Here, the body of the loop will be executed as long as code is not equal to 5 or x is not the string "back".
of course, to exit the loop, you must either set code to be 5 or set x to be "back" somewhere in the body of the loop.
 
ekte spiriopoulos
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fred Kleinschmidt wrote:
No, this is not correct.
First, why are "x" and "code" declared as static?
Second, you have a undefined symbol named Back.
What I think you want is

Here, the body of the loop will be executed as long as code is not equal to 5 or x is not the string "back".
of course, to exit the loop, you must either set code to be 5 or set x to be "back" somewhere in the body of the loop.
thanks a lot
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fred Kleinschmidt wrote:. . . to exit the loop, you must either set code to be 5 or set x to be "back" somewhere in the body of the loop.
You must set code to 5 and s to "back".

Augustus de Morgan's Law:-
¬(p ∧ q) ≡ ¬p ∨ ¬q
¬p ∧ ¬q ≡ ¬(p ∨ q)
∴ The termination condition for that loop is:-
¬(code ≠ 5 ∨ s ≠ "back")

¬(code ≠ 5 ∨ s ≠ "back") ≡ (by de Morgan's Law)
  ¬(code ≠ 5) ∧ ¬(s ≠ "back") ≡ (logic: ¬(p ≠ q) ≡ p = q)
     code = 5 ∧ s = "back "

[edit]Add: I think OP might want to replace that OR || operator with an AND &&.
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some people don't like, but consider using do-while loop. Maybe it is what best fits in your case. And I think CR is right about OP's wanted intention.
 
Fred Kleinschmidt
Bartender
Posts: 571
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:You must set code to 5 and s to "back". ...
[edit]Add: I think OP might want to replace that OR || operator with an AND &&.


I was just following the original code as written : pointing out that Back should have been quoted.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!