• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Help me with this Task

 
Ranch Hand
Posts: 54
Python Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Guys,

I was stuck in the task and I am unable to figure it out. I was asked to do something like this ,

while( var = GetNext() )
{
 ...do something with var
}

Could someone send me some coding sample that uses the above syntax? I know its a beginner level question, but hopefully, you can still help me.

Regards,
Ashish.
 
Carey Brown
Saloon Keeper
Posts: 9720
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, you don't say if it's not doing what you expect or exactly what you expect to happen.
 
Shaik Ashish
Ranch Hand
Posts: 54
Python Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The task was given me to as "While loop with assignment"

I think = is assignment operator whereas == is comparision operator

I Was told to write a small snippet code that utilizes that style, it is not intended to do any particular task.
 
Carey Brown
Saloon Keeper
Posts: 9720
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, you certainly could write
that would mean that booleanVariable would always be true inside the loop. Although this might work, the use of "=" where a boolean expression is expected will lead many readers to assume that you really meant to use "==", which in this case would be wrong. Here I've identified the variable and method as explicitly boolean but that is not the case with most code. This syntax should be avoided if at all possible. If you can't avoid it then make it abundantly clear what you are doing with a bold COMMENT.

Though more verbose, I would have suggested
 
Sheriff
Posts: 7123
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your task is to use an assignment in a while loop, The typical way to read a BufferedReader object is like this:
 
Sheriff
Posts: 17297
299
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"While loop with assignment" is not a task. Please provide the full task description so that people don't start making their own assumptions about what exactly it was you were asked to do. This will make it easier to give you an appropriate answer and not just guesses.
 
Seriously? That's what you're going with? I prefer this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic