Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java control statements

 
Achin Gupta
Greenhorn
Posts: 28
Java Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are the control statements like if(),while() etc are methods in java?
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They cannot return a value. They cannot have access modifier. They cannot be static. They cannot be invoked using a Class name or object. They cannot be declared abstract. Really is that your question and welcome to the ranch
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And beyond that... Java doesn't have functions, so it's meaningless to ask questions about whether something is or isn't a "function" in the context of Java.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They're not really like functions at all, other than having brackets after them - which is just an accident of syntax. How would you write a function (or method) to do what while does? That is, continually execute the block of code following it until a condition is true.

If you want to see a language where all the control structures are methods, though, have a look at Smalltalk (there are probably others). There, for example, a for loop is a method of the Integer class, which takes a block of code as an argument and executes it n times, where n is the receiver.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic