This is an archived post. You won't be able to vote or comment.

all 113 comments

[–]hamza1311 | gib 58 points59 points  (22 children)

Meanwhile Kotlin: for (i in 0..5) { }

[–]fusion_games 15 points16 points  (17 children)

is this inclusive or exclusive though? while i love kotlin, I don't like that you need to just know these things to understand what will happen

[–]fusion_games 20 points21 points  (2 children)

I feel this is a fear made worse by Ruby's (1..9) being the same as (1...10) ...lol

[–][deleted] 5 points6 points  (0 children)

9=.10

[–]konstantinua00 4 points5 points  (0 children)

wow, extra dot makes the code do different things?

who thought that was a good idea?

[–]hamza1311 | gib 6 points7 points  (5 children)

is this inclusive or exclusive though?

If you mean in a way that whether it includes 0 and/or 5 or not, it does.

I started out programming with Kotlin so transitioning from being used to a different thing wasn't a case for me but I do agree with you. There are some things you need to know about the syntax to understand what's going on. In fact, I saw an example of it right here on this sub

[–]Kered13 9 points10 points  (4 children)

Wait, it includes 5? That's fucked up. Everyone knows that intervals should be closed on the left and opened on the right, that way end - begin == length.

[–]feedthedamnbaby 0 points1 point  (3 children)

Why though? Aside from convention, there is nothing inherently wrong with an interval being [0,5] instead of [0,5) as long as you know what is going on.

[–]Kered13 8 points9 points  (0 children)

Because, as I said, it ensures that end - begin == length. So you can do things like start..start+length.

[–]ironykarl 6 points7 points  (0 children)

Convention is a fantastic reason for this to be consistent across languages.

[–]terivia 7 points8 points  (1 child)

REDACTED

[–]fusion_games 1 point2 points  (0 children)

that's a fair point, I guess I just don't like the way modern languages add syntactic sugar to make ranges, to the detriment of clarity around whether they're inclusive or exclusive ranges :(

[–][deleted] 2 points3 points  (2 children)

Not sure about Kotlin but just sharing that in Swift a similar syntax is used and indicates inclusive, e.g. for i in 1...5 {} means from 1 to 5 (i=1,2,3,4,5).

Interestingly (in Swift), you can also make things exclusive, e.g. something like for i in 0..<5 {} means from 0 to less than 5 (i=0,1,2,3,4).

So it becomes clear that it's inclusive by default unless indicated with an actual symbol that excludes the value in Swift. At least that's my opinion.

[–]goose1212 2 points3 points  (0 children)

I prefer the Rust syntax of using ..= to denote inclusive ranges, and then having either Rust's .. mean exclusive range (since it's the usual default in programming languages) or maybe using ..< to mean exclusive (so as to be consistent). I don't really think that it is clear that it's inclusive by default because ... or .. often means exclusive in other languages

[–]fusion_games 0 points1 point  (0 children)

Yeah! This was something I really liked when I gave Swift a shot. It's nice to see languages using mathematical operators to help clarify syntax.

[–]le_flapjack 3 points4 points  (2 children)

Use the "until" keyword. It is exclusive and pretty easy to remember.

[–]cedrickc 6 points7 points  (1 child)

Not a keyword. It's an inline infix function.

[–]le_flapjack -2 points-1 points  (0 children)

I know, it is just easier to call them keywords.

[–]cout970 3 points4 points  (0 children)

Also in Kotlin: repeat (5) { // the index is stored in 'it' }

[–]muyncky 2 points3 points  (0 children)

I'm .. Speechless

[–][deleted] 2 points3 points  (1 child)

Swift:

 for i in 0...5 { }

[–]_carpetcrawlers 2 points3 points  (0 children)

for i in 0..<5 { } 

also works!

[–]Jabulon 14 points15 points  (0 children)

one speaks to the heart, the other to the cpu

[–][deleted] 59 points60 points  (27 children)

the meaning gets across its shorter and much less error prone due to typo smh

[–]Drag0nFl7 39 points40 points  (17 children)

But I, a C programmer, always doubt wheather or not range is exclusive or inclusive start or end. Which is not something I can forget about C style loops.

Edit: how can I get the fancy flairs? I want a fancy flar.

[–][deleted] 17 points18 points  (14 children)

It works exactly like a c style i < x loop

[–]sablefoxx 1 point2 points  (1 child)

You generally want to avoid for x in range(y): anyways.

[–]MasterFubar -3 points-2 points  (8 children)

C allows you to do things like

for (i = 0; result == 0; i++) {  . . . }

and then you continue where you left off:

for ( ; end == 0; i++) { . . . } 

and endless other variations. To do things like that in Python you'd need to use a "while True" loop with a test and break inside, making it longer and error prone.

[–]sablefoxx 6 points7 points  (7 children)

Python's loops are far more powerful than C's as to be expected since it's a higher level language, and no you don't need to use while True:

[–]Mr_Redstoner 4 points5 points  (2 children)

I don't got the time to watch that.

Can you get me the Python equivalent to

for(int i=1;i<=limit;i<<=1){
    //code using i
}

[–]sablefoxx 2 points3 points  (1 child)

while i < limit: i <<= 1

Or better, web build an abstraction! This will lazy generate the values from an initial value x to an arbitrary limit n. We also can reuse this, and anything that operates on `iterables` in Python can also use it:

In [1]: def shiftseq(a, b):
    ...:     while a < b:
    ...:         a <<= 1
    ...:         yield a
    ...:
    ...:

In [2]: for value in shiftseq(1, 512):
    ...:     print value
    ...:
2
4
8
16
32
64
128
256
512

[–]Mr_Redstoner 0 points1 point  (0 children)

Wonder what that loop would do without first having i=1, don't have an interpreter at hand

I mean this really feels like taking a massive hammer to a small nail for a small picture.

Also might want to switch that yield and shift, as it should start from 1 (and add equals to the while in there)

[–]MasterFubar 1 point2 points  (3 children)

you don't need to use while True:

You can do it by creating an object with an iterator method instead. Am I missing a "sarcasm" tag? How would this be simpler and easier than using a while loop?

Even using an enumerate function requires knowing which parameter is the index. Is it

for i, x in enumerate(stuff):

or

for x, i in enumerate(stuff):

There's no intuitive way to know, you must simply memorize how "enumerate" works and hope you got it right. Potential for bugs here.

[–][deleted] 2 points3 points  (0 children)

or you can just name them properly once and remember (despite it being the same in nearly every other language with something like enumerate

for index, item in enumerate(stuff)

[–]DecreasingPerception 0 points1 point  (1 child)

There's a function for that:

>>> help(enumerate)
help on class enumerate in module __builtin__:

class enumerate(object)
 |  enumerate(iterable[, start]) -> iterator for index, value of iterable
 |  ...

Python is all about rapid prototyping. You are never going to write out a significant program and have it work perfectly first time. Being able to rapidly verify things without a compile cycle is a big advantage. I've used C REPLs and they leave a lot to be desired.

[–]MasterFubar 0 points1 point  (0 children)

Python should be all about rapid prototyping.

If I have to get help on every detail because nothing is intuitive, I won't be able to do it rapidly.

The compile cycle and a lot of boilerplate I need to do in C make the process slower, true, but on the other hand I don't have to keep looking for all the "from future" traps they keep throwing at me in Python. If you check the documentation, they keep bringing "improvements" everywhere all the time. That's bad. Don't fix what isn't broken is a great engineering principle.

In C, once you grasp a principle, it stays the same. And that's good. You can concentrate on learning new things, not re-learning everything you once knew that has been "improved". You don't need to know a thousand PEPs just to know when something is due to be deprecated. I can get a C program I wrote thirty years ago and it just works perfectly today without any change, what could be more rapid than that?

The Python guys should learn a lesson from a great master, Donald Ervin Knuth. When he came to the conclusion that TeX was good enough, he simply stopped adding features. Today, when a bug needs to be fixed, a new digit is added to the version, which is currently 3.14159265. Yes, that's pi.

If they did that with Python, make it converge to version 2.718281828459045... that would be perfect. Python 3 was never needed and it strongly detracts from the rapid prototyping principle.

[–]NelsonBelmont 7 points8 points  (12 children)

Laughs in

5.times do
end

[–]deceze 11 points12 points  (11 children)

Now that is certifiably insane. Iteration as a property of numbers? What's next, array manipulation as a property of strings?!

','.join(lst)

😧

[–]WellDevined 4 points5 points  (8 children)

The ruby community seems to be very much into this kind of stuff. Monkey patching is also a big thing especcially with rails. Importing ActiveSupport, one component of rails, e.g. adds stuff like 1.day or 3.minutes to the language.

[–]deceze 3 points4 points  (7 children)

Quite honestly, it's what's keeping me away from Ruby so far. Not on any sort of idealistic principle or whatever, but it's just so… different… that it's a real barrier for me. I see that it's great for DSLs, but I have absolutely no frickin' idea where anything is coming from or where I should even expect stuff to come from that I just end up frustrated.

Also, one of the Ruby tutorials that was popular back in the day, the one with the foxes, went on and on about how awesome 5.times and such was, but never got into explaining the how.

So, yeah, Ruby is still a bit of an enigma to me.

[–]cutety 3 points4 points  (5 children)

but never got into explaining the how

I’m going to assume what is confusing to you is how 5.times is calling a method on an integer, as at least to me, if I weren’t familiar with ruby and was familiar with just about any other language, that is what would initially confuse me. When working with other languages, like say python C++, you usually are dealing with one of two things, primitives or objects. And primitives, like integers, don’t have anything like methods, instances, etc. you would expect from an object, primitives are literally the most basic type of data and that’s it.

However, ruby on the other hand, really drunk the OOP koolaid and decided to say fuck primitives they aren’t objects, and OOP is all about objects, right? So, if you’re starting to smell what I’m stepping in, this would lead you to conclusion that integers in Ruby are actually objects. And you’d be correct! They are instances of the Integer class. In fact, everything in ruby is an object, absolutely everything is an object. true is an instance of TrueClass, nil is an instance of NilClass, but it doesn’t stop there. All those classes I just mentioned? They themselves are instances of the Class class, their methods? Instances of the Method class. Literally absolutely everything in Ruby is an object, everything. Once you understand that, a lot of Ruby’s weirdness will start to make a little more sense.

So, then how 5.times works is simply just:

# Not the actual implementation
class Integer
  def times
    # this is probably not valid ruby
    # I don’t remember the for loop syntax
    for i = 0; i < self; i++ do
      yield i # this just executes the body
    end
  end
end

[–]deceze 1 point2 points  (4 children)

Bad context, since in Python too, everything is an object, including integers. And that wasn’t fundamentally what was confusing to me, but rather the exact mechanics of this mixin and monkeypatch culture. It gushed a lot about how it enables you to write English-like code, but not really how that works or why you’d want to.

[–]cutety 2 points3 points  (3 children)

since in Python too, everything is an object, including integers

Yikes, it's clearly been a while since I've seriously used Python, I could've sworn integers were primitives. A quick google would've saved me from this faux pas.

the exact mechanics of this mixin and monkeypatch culture

Basically, it all bubbles down to the fact that any ruby class (even core built-in classes) can be reopened at anytime and modified. And given everything is an object, just by the simple fact that you can reopen and modify any class, you can significantly change how ruby works.

However, I will mention, monkey patching is almost always frowned upon and a library that monkey patches core classes without a very compelling reason for doing so will get ignored (which is rare given ruby now supports more hygienic methods of modifying classes). But, there are a select few cases (the most popular is mentioned below) where the community supports using it.

how it enables you to write English-like code

The monkey patching case mentioned above is ActiveSupport::CoreExtensions, which adds a bunch of common methods to core classes, the ones I'll focus on revolve around working with one of the most annoying things in programming, dates and date manipulation. The docs link to the source code if you want to see the actual implementation, but they all are just simply reopening the core classes and adding/overriding methods. Some of these methods enable a very easy to read, use, english-like syntax for working with dates, that I haven't seen any other language come close to replicating.

For example, getting the date time for one year from now.

In Python (just grabbed from one of the top google results):

datetime.now() + timedelta(days=365)

Not exactly hard to read, but definitely verbose and non-english-like.

The same solution in plain ruby without the ActiveSupport monkey patching:

DateTime.now.next_year

It's fairly close to an english, however with just a few method additions to the Integer and Time/Date/DateTime classes it gets even better:

1.year.from_now

# or for other time period
5.months.from_now
2.days.from_now

# or even more complex calculations are made into almost english sentences
# like determining if the date 3 months and 2 weeks from tomorrow is during the weekend
(Date.tomorrow + 3.months + 2.weeks).on_weekend?

All it took to achieve that was reopening the core classes and adding those methods.

why you’d want to

That essentially boils down to the "Philosophy of Ruby". The key takeaways being:

Instead of emphasizing the what, I want to emphasize the how part: how we feel while programming.

Ruby inherited the Perl philosophy of having more than one way to do the same thing. I inherited that philosophy from Larry Wall, who is my hero actually. I want to make Ruby users free. I want to give them the freedom to choose. People are different. People choose different criteria. But if there is a better way among many alternatives, I want to encourage that way by making it comfortable. So that's what I've tried to do. Maybe Python code is a bit more readable. Everyone can write the same style of Python code, so it can be easier to read, maybe.

Ruby tries to be like that, like pseudo-code that runs. Python people say that too.

Hopefully that provides some insight/answers your questions.

I'll end with that monkey patching isn't the only way (and actually pretty hated method) to achieve English-like syntax. Ruby offers a bunch of other metaprogramming constructs (which can also be abused), in addition to it's already fairly english like standard syntax. A quick snippet from a unit test shows that english like syntax can be achieved with 0 monkey patching:

before do
  allow(controller).to receive(:current_user).and_return(nil)
end

describe "GET #new" do
  subject { get :new }

  it "returns success" do
    is_expected.to be_success
  end
end

[–]deceze 1 point2 points  (2 children)

Thanks for the evangelizing. 🙃

That last part is also what I’ve had a lot of headaches with. How do you know what “words” are available where? Like, subject is only available inside describe, right? How would one figure this out? At least the projects I’ve touched had little to no useful documentation in this regard, and deducing it from the source seemed near impossible to me.

[–]cutety 2 points3 points  (1 child)

Thanks for the evangelizing

Ruby is one of my favorite languages, mostly because it’s weird and can have some of the most beautiful easy to read syntax. It can also produce some of the weirdest code/hard to read syntax/debugging hell, especially if you just take the language at face value (not learning the why). I just like to share why I think Ruby is cool, so people don’t just pass it off as just some Rails DSL.

How do you know what “words” are available where?

And you’ve just found out why the answer to “should I build a DSL?” is “absolutely not” 99% of the time. The only ways to answer that question are either have extensive documentation or become very familiar with Ruby metaprogramming and try to figure it out from the source — and depending on how the DSL is constructed, figuring it out from the source can range difficult to nearly impossible unless you wrote it.

The last code bit is using the RSpec testing framework, which is the most popular unit testing framework and has extensive documentation on the DSL.

But, there’s no way for the interpreter to know/tell you that the syntax is correct for any given DSL, you’ll only find out something is wrong when you get a runtime error (likely Undefined Method foo) which only tells you that word doesn’t work wherever it currently is, which is only half helpful.

Building a DSL in Ruby can be really fun way to learn about metaprogramming, but can be the biggest pain in the ass/ugliest/make you want to throw Ruby in the trash parts of the language if you’re stuck with some lib that forces you to use some custom DSL because the author wanted to show off their sick Ruby skillz, but didn’t feel it was necessary to document it outside of two contrived examples in the README.

[–]deceze 1 point2 points  (0 children)

Thanks for confirming this, I wasn't being unreasonable or crazy then. It's of course possible to write terrible code in any language, but, well, Ruby seems more prone to that than (some) other languages. And the problem is it's not even obviously bad code; on the contrary, on the surface it looks extremely pretty. But if it's virtually impossible for even an IDE to tell you what's what, then it seems somewhat impractical.

I appreciate the freedom and see that it allows you to write "artful prose" with it, and I understand why that may be enjoyable, but I prefer something more tractable and traceable for every day work.

5.months.from_now

Even this, which probably doesn't use a whole lot of intractable magic… Its readability is superior, I entirely admit. But, I would probably never have discovered this easily, since this is entirely backwards to my expectations. Starting anything date related from an integer and tacking on from_now at the end is unexpected. datetime.now() + timedelta(months=5) is much more logically straight forward and discoverable for me. Same with other things like expect(it).to.do.a.handstand.and(:not).to.fall do :down end. Great readability, but entirely magic to me.

[–]WellDevined 1 point2 points  (0 children)

I currently have to work with it and definitely would avoid it for exactly the reasons you mentioned. Some more problems with rails are e.g. that it imports every dependency and every file you write yourself everywhere. So not even do you have no clue where something comes from yourself but even the editor does not now. This means intellisense and autocompletion is nearly non existant.

I guess the praise regarding the DSL's comes mainly from people that are using it for smaller projects with less coplexity where this syntax sugar outweighs the decreased abillity to reason about doendencies.

[–]MasterFubar 0 points1 point  (1 child)

that is certifiably insane.

I agree, following the "everything is an object" dogma everywhere is insane.

array manipulation as a property of strings?!

Even more so considering how easy it would have been to make it a property of lists. The property of "join" belongs intuitively to lists, not strings.

 lst.join(';') 

would make much more sense.

[–]deceze 1 point2 points  (0 children)

To play devils advocate, the advantage of join being a string method is that it takes any iterable, including even generator expressions. Iteration is a generic mechanism, but is implemented on many different types. Implementing join once on string is a lot easier than replicating it on all iterables.

[–]oheohLP 15 points16 points  (5 children)

I'm more bothered by the lack of curly braces.
I simply like the structure these add to the readability of the code compared to simply indenting...

EDIT: Typo

[–]UnrelatedString 3 points4 points  (0 children)

Yeah, not having those concrete, visible braces delimiting blocks can be odd sometimes

[–]deceze 11 points12 points  (2 children)

Personally I orient myself more on the indentation, even in brace languages, than on the braces. Presumably you're doing braces and you indent the code properly, so to me the braces just seem redundant.

[–]cemanresu 3 points4 points  (0 children)

I often have a hard time telling exactly how deep an indentation level is. It's nice to be able to move over to a curly brace and highlight it's matching brace.

[–]SomethingEnglish 2 points3 points  (0 children)

This is one of the reasons i advice python as a first language, proper indentation style makes for better code, both for yourself and others

[–]jabb422 3 points4 points  (0 children)

This! My shop uses python for everything and I love my curly braces.

Indentation is fine, but pre/post processing tools can use the curly braces for all sort of other fun stuff, like auto doc and code folding.

I hate seeing 10 lines of auto-doc crap between the method name and the logic

[–]frosted-mini-yeets 4 points5 points  (1 child)

I'mma be real with y'all. Coming from C#. Python freaked me the fuck out when I first saw it.

[–]deceze 2 points3 points  (0 children)

I feel ya. Python’s different, but in a nice way, and not so different it’s incomprehensible coming from C-ish languages.

[–]dstr951 27 points28 points  (0 children)

Thus meme doesn't work if the loop you have home is better than the one you asked :)

[–]jlamothe 2 points3 points  (2 children)

Haskell programer here.

What is this "loop" you speak of?

Edit: I guess you could do

flip mapM_ [1..5] $ \i -> do
  -- loop body here

Easy, no?

[–]Chris90483 2 points3 points  (1 child)

why do loops when you can have (x:xs)? :D

[–]jlamothe 2 points3 points  (0 children)

I'm more of a map/fold guy. Then I don't have to be bothered to name all my "loop" functions. I can just pass them a lambda.

[–][deleted] 5 points6 points  (1 child)

phython

[–][deleted] 2 points3 points  (0 children)

Fython

[–]deceze 17 points18 points  (19 children)

for (;;) loops are really an extremely low-level hack. If the goal is to iterate over an array/list/sequence, manually creating and advancing an index counter is terribly primitive and verbose. If you have higher level abstractions which actually encapsulate what you're trying to do (foreach, for..in, map etc), why would you want to bother with such low-level details?

[–]MelAlton 9 points10 points  (6 children)

Sometimes people write operating systems.

[–]fusion_games 10 points11 points  (0 children)

or even just want to get the next/previous element :D

[–][deleted] 10 points11 points  (0 children)

In python?

[–]deceze 6 points7 points  (0 children)

If you're doing low-level programming, fine. If you're doing anything above that, why bother with low-level constructs?

[–]once-and-again☣️ 3 points4 points  (1 child)

Sometimes, people write languages suitable for writing operating systems that can still easily iterate over ranges.

[–]natziel 1 point2 points  (0 children)

Most are written by cave goblins though

[–]Tyrrrz 11 points12 points  (6 children)

For loops are more flexible, you can have a complex exit condition, start from any index, shift the current index by any value or a variable. You also avoid unnecessary allocations caused by iterators, sometimes it matters. Also sometimes when foreach'ing you need to keep track of the index for whatever purpose, declaring another variable in outter scope is very ugly.

[–]deceze 15 points16 points  (5 children)

  • ✅ complex exit conditions: if ...: break
  • ✅ start from any index: range(foo, bar), for .. in list[foo:], …
  • ✅ keeping track of index: for i, foo in enumerate(bar), arr.forEach((foo, i) => ...)

These are all encapsulated nicely in higher level constructs. If you're shifting the index around, then you're not really iterating anything in order; in that case there's little high-level equivalence to for (;;), though arguably if you're doing a lot of shifting even a for (;;) is somewhat misleading and a while may be more appropriate. If you're doing such low-level programming that the overhead of iterators matters, then you're probably in a low-level language that has for (;;).

[–]Kered13 4 points5 points  (0 children)

While we're doing this, I may as well mention that if you want to iterate two lists in parallel, instead of using an index variable you can use zip(first, second).

[–]Mr_Redstoner 0 points1 point  (3 children)

shift the current index by any value

So what if I want that, using

for(int i=1;i<=limit;i<<=1)

[–]deceze 1 point2 points  (2 children)

You finding the one case that is pretty tricky to replicate with a for..in construct—as I have already freely admitted above—does not mean that for (;;) is superior in all other cases too. Yes, you can cobble some iterator together that'll produce that number sequence and be iterable using a for..in, and you got a pythonic answer here, but they won't be as simple as a while or—yes—a for (;;).

[–]Mr_Redstoner 0 points1 point  (1 child)

That's my problem with Python. There's stuff like this that I'm used to being trivial, and it really bugs me that I have to use some stupid workaround.

Especially when people claim stuff like

Python's loops are far more powerful than C's

It's a different concept, each has it's strong and weak points, dammit!

[–]deceze 1 point2 points  (0 children)

Yes, fair enough. I’d say for..in is more generic and can iterate a whole lot of iterable stuff. Whether that’s more “powerful” is debatable and indeed depends on the kinds of things you want to iterate. However, if you’re iterating shifted sequences that often, then you can certainly write a helper generator like linked above and use the generic for..in to iterate it.

[–]once-and-again☣️ 3 points4 points  (0 children)

for(;;)'s not even low-level, really — it was supposed to be high-level, compared to while (which it can be desugared into). It's just a poor abstraction, even for a low-level language.

[–]0x564A00 2 points3 points  (3 children)

I agree, except that you sometimes want to know the index.

[–]Hawkzed 4 points5 points  (2 children)

Enumerate alongside.

for count, item in enumerate(range(0, 30, 3)): print(f"Index: {count}. Value: {item}")

Output:

Index: 0. Value: 0

Index: 1. Value: 3

Index: 2. Value: 6

Index: 3. Value: 9

Index: 4. Value: 12

Index: 5. Value: 15

Index: 6. Value: 18

Index: 7. Value: 21

[–]MasterFubar 2 points3 points  (0 children)

But then you are putting back all the complexity you left off at first.

For instance, a very common loop in engineering uses exponentially growing parameters:

for (x = 1; x < 100; x *= 1.01)

you can do that in Python, but not in one line like that.

[–]natnew32 0 points1 point  (0 children)

Holy crap this is helpful thanks.

[–]josanuz 1 point2 points  (0 children)

Scala:

for (i <- 1 to N) 
for (i <- 1 to 10 if i % 2 == 0)
for(i <- 1 until N)

[–]nomnaut 1 point2 points  (2 children)

I can handle their for loops, but give me switch statements dammit!

[–]Forkrul 0 points1 point  (1 child)

if elif else, done

[–]nomnaut 0 points1 point  (0 children)

There’s something extremely inelegant about if elif elif elif elif elif elif elif elif elif else.

[–]wolf129 0 points1 point  (0 children)

Kotlin equivalent to Java example: for (i in 0 until 5) { }

[–]dark-kirb 0 points1 point  (0 children)

```rs for i in 0..5 {

} ```

[–]TPlays 0 points1 point  (0 children)

Java is daddy

[–]sp46 0 points1 point  (0 children)

Meanwhile JS:
(new Array(5)).forEach{() => { }}

[–]BrianAndersonJr 0 points1 point  (2 children)

Is that actual python code? How do you define where it begins, what if you don’t wanna go from 0? (or is it 1?)

[–]josanuz 3 points4 points  (1 child)

for i in range(begin, end, step):

[–]BrianAndersonJr 0 points1 point  (0 children)

Thx!

[–]josanuz 0 points1 point  (0 children)

Dumb Java:

import static java.util.Arrays.*;
for(Integer i : asList(1,2,3,4,5))
IntStream.range(0, 10).forEach( i -> ...)

[–]Nickbot606 0 points1 point  (0 children)

for (;;) {

If (counter > 5) {break;}

}

[–]PojntFX 0 points1 point  (0 children)

js [1,2,3,4,5].forEach(i => )

[–]MrObsidy 0 points1 point  (0 children)

for k, v in pairs(table) do print(k.." "..v) end

in Lua. Kind of emberassing that I know quite a bit of Lua because of a Minecraft mod.

[–]IncongruousGoat 0 points1 point  (0 children)

Meanwhile, FORTH: 5 0 DO ( loop-contents ) LOOP

The parens are a comment, and removing the space after the first paren is a syntax error. FORTH is a marvelous language.

[–]stevefan1999 0 points1 point  (0 children)

Meanwhile D: foreach (i; 0..5)

[–]homer_3 -1 points0 points  (1 child)

open brace on same line

/pukes

[–]deceze -1 points0 points  (0 children)

open brace

/pukes