#Any way to use define in Java

1 messages · Page 1 of 1 (latest)

orchid flame
#

I know, i can make functions to read IO, or many algos, but its not about that, what i want to do is define a word with a line of code..
for eg..,
#define rep(i,a,b) for(int i=a;i<b;++i)
I want a shortcut like this in java, is there any way?

crimson rampartBOT
#

<@&987246399047479336> please have a look, thanks.

crimson rampartBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

runic turtle
#

not like that, but u can create methods that behave the same way ( in for example helper classes )

#

or interface(s)

wheat stump
#

or use functional programming

#
repeat(a, b, i -> {
 ... 
});
#
public static void repeat(int a, int b, IntConsumer consumer) {
  for (int i = a; i <= b; i++) {
    consumer.accept(i);
  } 
}
fickle hawk
#

Technically speaking C can't do that either

#

C just has a standard "preprocessor" that runs before normal language rules take effect

#

You can actually run just that preprocessor before compiling your Java code too

#

That wouldn't be smart, but you can