[Question]
  [
# Your very own "for" instruction
Assuming you have the following input : `a, b, c, d`
Input can be in one-line using any format "a/b/c/d" or "a,b,c,d" etc..
You can also have 4 inputs.
You must code the following behaviour (pseudo-code here) :
```
var i = <a>
while (i <b> <c>)
    print i
    i = i + <d>
    print "\n"
```
Here are some tests cases :
```
input : 1,<,10,1
output :
1
2
3
4
5
6
7
8
9
```
One more :
```
input : 20,>,10,1
output :
20
21
22
23
24
25
26
27
...
infinite loop / program crashes
```
* `a` is an **integer**, the initial value of `i`.
* `b` is a **string** or a **char**, it can't be something else, the comparator used in the ending condition of the
`for` loop.
`b` can and **must** be one of the following strings :
```
- ">"
- "<"
```
* `c` is an **integer**, the number used in the ending condition of the `for`
loop.
* `d` is an **integer** that is added to i at every loop.
This is code-golf, the shortest answer wins !
  
[Answer]
## JavaScript (ES6), ~~44~~ ~~43~~ 56 bytes
*Saved 1 byte thanks to ETHproductions*  
*Edit: fixed to comply with output requirements*
```
(a,b,c,d)=>{for(s='';eval(a+b+c);a+=d)s+=a+`
`;alert(s)}
```
### Test
```
let f =
(a,b,c,d)=>{for(s='';eval(a+b+c);a+=d)s+=a+`
`;alert(s)}
f(1,'<',7,2)
```
[Answer]
## Javascript (ES6), ~~47~~ ~~42~~ 48 Bytes
Wanted to make the for version but someone was faster, so here's the recursive version.
```
(b,c,d)=>F=a=>eval(a+b+c)&&console.log(a)|F(a+d)
```
You need to add `f=` before and call it like `f(b,c,d)(a)`.
*Many thanks to Arnauld for the awesome golf.*
*`alert` changed to `console.log` because of output specification*
[Answer]
# Pure bash, 35
I assume its OK just to plug the parameters into the standard for loop:
```
for((i=$1;i$2$3;i+=$4));{ echo $i;}
```
[Try it online](https://tio.run/#VIul3).
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 12 bytes
```
Ṅ+⁶µ⁴;⁵¹vµ¿t
```
[Try it online!](https://tio.run/nexus/jelly#ASYA2f//4bmEK@KBtsK14oG0O@KBtcK5dsK1wr90////NP8iPCL/MTH/Mg "Jelly – TIO Nexus")
Jelly has a lot of ways to tersely do iteration, create ranges, etc.. However, mirroring C++'s behaviour exactly is fairly hard, due to special cases like the increment being 0, the loop ending before it starts (due to the inequality being backwards), and the increment going in the wrong direction (thus meaning the exit condition of the loop can't be met naturally). As such, this solution is basically a direct translation of the C++, even though that makes it rather more low-level than a Jelly program normally is. Luckily, C++ has undefined behaviour on signed integer overflow (the question uses `int`), meaning that a program can do anything in that case, and thus there's no need to try to mimic the overflow behaviour.
## Explanation
```
Ṅ+⁶µ⁴;⁵¹vµ¿t
   µ     µ¿   While loop; while ((⁴;⁵¹v) counter) do (counter = (Ṅ+⁶)counter).
    ⁴;⁵       Second input (b) appended to third input (c), e.g. "<10"
        v     Evaluate, e.g. if the counter is 5, "<10" of the counter is true
       ¹      No-op, resolves a parser ambiguity
Ṅ             Output the counter, plus a newline
 +⁶           Add the fourth input (d)
           t  Crashes the program (because the counter is not a list)
```
Crashing the program is the tersest way to turn off Jelly's implicit output (otherwise, it would output the final value of the counter); it generates a bunch of error messges on stderr, but we normally consider that to be allowed.
Incidentally, the loop counter is initialised with the current value before the loop starts. As the loop appears at the start of the program, that'll be the first input.
[Answer]
# [Python 2](https://docs.python.org/2/), 50 bytes
```
a,b,c,d=input()
while eval(`a`+b+`c`):print a;a+=d
```
[Try it online!](https://tio.run/nexus/python2#@5@ok6STrJNim5lXUFqioclVnpGZk6qQWpaYo5GQmKCdpJ2QnKBpVVCUmVeikGidqG2b8v9/tIGOuo26jqGBjlEsAA "Python 2 – TIO Nexus")
[Answer]
## R, 63 bytes
```
function(a,b,c,d)while(do.call(b,list(a,c))){cat(a,"\n");a=a+d}
```
[Answer]
# Java, 58 bytes
```
(a,b,c,d)->{for(;b>61?a>c:a<c;a+=d)System.out.println(a);}
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~22~~ 20 bytes
```
[D²`'>Q"‹›"è.V_#D,³+
```
[Try it online!](https://tio.run/nexus/05ab1e#@x/tcmhTgrpdoNKjhp2PGnYpHV6hFxav7KJzaLP2//@GBlzRxjrqduqxXLpGAA "05AB1E – TIO Nexus")
**Explanation**
```
[                       # start loop
 D                      # copy top of stack (current value of a)
  ²`                    # push b,c to stack
    '>Q                 # compare b to ">" for equality
       "‹›"             # push this string
           è            # index into the string with this result of the equality check
            .V          # execute this command comparing a with c
              _#        # if the condition is false, exit loop (and program)
                D,      # print a copy of the top of the stack (current value of a)
                  ³+    # increment top of stack (a) by d
```
[Answer]
# SmileBASIC, 53 bytes
```
INPUT A,B$,C,D
S=ASC(B$)-61WHILE S*A>S*C?A
A=A+D
WEND
```
Explanation:
```
INPUT A,B$,C,D
IF B$=="<" THEN S=-1 ELSE S=1 'get comparison direction
I=A
WHILE S*I>S*C 'loop while I is less than/greater than the end
 PRINT I
 INC I,D
WEND
```
This uses the fact that `X<Y` is the same as `-X>-Y`
[Answer]
# [Stacked](https://github.com/ConorOBrien-Foxx/stacked), 34 bytes
```
@d@c@b[show d+][:c b tofunc!]while
```
[Try it online!](https://tio.run/nexus/stacked#@2@ooG6jrmBooGDE5ZDikOyQFF2ckV@ukKIdG22VrJCkUJKfVpqXrBhbnpGZk/r/PwA "stacked – TIO Nexus") (Testing included.) This is a function that expects the stack to look like:
```
a b c d
```
For example:
```
1 '<' 10 2
@d@c@b[show d+][:c b tofunc!]while
```
## Explanation
```
@d@c@b[show d+][:c b tofunc!]while
@d@c@b                               assign variables
               [............]while   while:
                :c                   duplicate "i" and push c
                   b tofunc!         convert b to a function and execute it
      [.......]                      do:
       show                          output "i" without popping
            d+                       and add the step to it
```
[Answer]
## Plain TeX, 88 bytes
```
\newcount\i\def\for#1 #2 #3 #4 {\i#1\loop\the\i\endgraf\advance\i#4\ifnum\i#2#3\repeat} 
```
The command `\for` provides the requested function. Save this as `for.tex` and then run it and enter the variable values at the command line: `pdftex '\input for \for 1 < 5 1 \bye'` The variable values must be separated by spaces.
[Answer]
# [Python 2](https://docs.python.org/2/), 45 bytes
```
exec"i=%d\nwhile i%c%d:print i;i+=%d"%input()
```
[Try it online!](https://tio.run/nexus/python2#@59akZqslGmrmhKTV56RmZOqkKmarJpiVVCUmVeikGmdqQ2UUlLNzCsoLdHQ/P/fUEfdRl3H0EDHEAA "Python 2 – TIO Nexus")
A very literal implementation of the spec. Takes the code template, substitutes in the inputs via string formatting, and executes it.
[Answer]
# C++, 80
Whoops, this is `C++` not `C`. Was a bit confused by the question.
```
void f(int a,char b,int c,int d){for(;b==62?a>c:a<c;a+=d)cout<<a<<endl;}
```
[Answer]
# C, 52 51 bytes
-1 byte thanks to [H Walters](https://codegolf.stackexchange.com/users/58514/h-walters)
```
f(a,b,c,d){for(;b&2?a>c:a<c;a+=d)printf("%d\n",a);}
```
[Try it online!](http://ideone.com/N455xt)
[Answer]
# Python 3, 52 bytes
```
def f(a,b,c,d):
 while[a>c,a<c][b<'>']:print(a);a+=d
```
**[repl.it](https://repl.it/FVyU)**
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 14 bytes
```
W Va.b.ca:d+Pa
```
Takes four command-line arguments. Supports negative & floating point numbers and comparison operators `< > = <= >= !=`. [Try it online!](https://tio.run/nexus/pip#@x@ZGK4QVqmXpJccmaIdUPn//38jg/92tv8NDf7rGgEA "Pip – TIO Nexus")
```
                a,b,c,d are cmdline args
W               While loop with the following condition:
  Va.b.c          Concatenate a,b,c and eval
            Pa  Print a with newline (expression also returns value of a)
        a:d+    Add d to that and assign back to a
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 bytes
```
ḢṄ+⁹;µV¿
```
This is a dyadic link that takes **a,b,c** as its left argument and **d** as its right one. Output may be infinite and goes to STDOUT.
[Try it online!](https://tio.run/nexus/jelly#ASkA1v//4bii4bmEK@KBuTvCtVbCv/8xLOKAnTwsMTAgw6cgMSDhuZkg4oCc/w "Jelly – TIO Nexus")
### How it works
```
ḢṄ+⁹;µV¿  Dyadic link.
          Left argument:  a,b,c (integer, character, integer)
          Right argument: d     (integer)
       ¿  While...
      V     the eval atom applied to a,b,c returns 1:
     µ       Combine the links to the left into a chain and apply it to a,b,c.
Ḣ              Head; pop and yield a from a,b,c.
 Ṅ             Print a, followed by a linefeed.
  +⁹           Add a and the right argument (d) of the dyadic link.
    ;          Concatenate the result and the popped argument of the chain,
               yielding a+d,b,c.
```
[Answer]
# Python 3, 61 bytes
One liner:
```
e=input;exec(f'i={e()}\nwhile i{e()}{e()}:print(i);i+={e()}')
```
[Answer]
## Common Lisp, ~~82~~ ~~80~~ ~~79~~ ~~73~~ 64 bytes
```
(defmacro f(a b c d)`(do((i,a(+ i,d)))((not(,b i,c)))(print i)))
```
## Test
```
(f 1 < 10 1)
1 
2 
3 
4 
5 
6 
7 
8 
9 
NIL
CL-USER> 
```
-9 bytes thanks to PrzemysławP.
[Answer]
# [Haskell](https://www.haskell.org/), ~~66~~ 64 bytes
```
f a b c d|last$(a<c):[a>c|b>"<"]=print a>>f(a+d)b c d|1<3=pure()
```
[Try it online!](https://tio.run/nexus/haskell#@5@mkKiQpJCskFKTk1hcoqKRaJOsaRWdaJdck2SnZKMUa1tQlJlXopBoZ5emkaidoglRa2hjbFtQWpSqofk/NzEzT8FWIU3BQAGoXsFSweg/AA "Haskell – TIO Nexus") Usage:
```
Prelude> f 0 "<" 9 2
0
2
4
6
8
```
[Answer]
# Bash (+Unix Tools), 29 bytes
**Golfed**
```
bc<<<"for(x=$1;x$2$3;x+=$4)x"
```
**Test**
```
./forloop 1 '<' 10 1
1
2
3
4
5
6
7
8
9
```
[Answer]
# Ruby, ~~43~~ 41 bytes
```
->a,*i,d{a=d+p(a)while eval"%s"*3%[a,*i]}
```
If `b` can be taken in as a *Ruby symbol* instead of a string, you get **38 bytes**:
```
->a,b,c,d{a=d+p(a)while[a,c].reduce b}
```
[Try either solution online!](https://repl.it/FWQd/1)
[Answer]
# PHP, ~~69~~ 65 bytes
```
for(list(,$i,$b,$c,$d)=$argv);$b<"="?$i<$c:$i>$c;$i+=$d)echo"$i
";
```
Run with '-r'; provide command line arguments as input.
For ~~just one byte more~~ 4 more bytes, I can take every operator:
```
for(list(,$i,$b,$c,$d)=$argv;eval("return $i$b$c;");$i+=$d)echo"$i
";
```
Yeah, evil eval. Did you know that it can return something?
---
Shorthand destructuring `[,$i,$b,$c,$d]=$argv;` would save 4 more bytes;  
but PHP 7.1 postdates the challenge.
[Answer]
# [Perl 6](http://perl6.org/), 44 bytes
```
{.say for $^a,*+$^d...^*cmp$^c!= $^b.ord-61}
```
### How it works
```
{                                          }  # A lambda.
          $^a                                 # Argument a.
             ,*+$^d                           # Iteratively add d,
                   ...^                       # until (but not including the endpoint)
                       *cmp$^c                # the current value compared to c
                                              # (less=-1, same=0, more=1)
                              != $^b.ord-61.  # isn't the codepoint of the b minus 61.
 .say for                                     # Print each number followed by a newline.
```
If it's okay to return a (potentially infinite) sequence of numbers as a value of type `Seq`, instead of printing the numbers to stdout, the `.say for` part could be removed, bringing it down to 35 bytes.
[Answer]
# Clojure, ~~66~~ 63 bytes
```
#(when((if(= %2"<")< >)% %3)(println %)(recur(+ % %4)%2 %3 %4))
```
-3 bytes by factoring out the `loop`. I'm "abusing" the init parameter to act as the running accumulator.
Recursive solution (with TCO). See comments in pregolfed code. I tried a non-TCO recursive solution, and it ended up being 67 bytes.
I'd love to see this beat in Clojure! I think this is the smallest I can get it.
```
(defn my-for [init-num com-str com-num inc-num]
  (let [op (if (= com-str "<") < >)] ; Figure out which operator to use
    (when (op init-num com-num) ; When the condition is true, print and recur
      (println init-num)
      (recur (+ init-num inc-num) com-str com-num inc-num))))
    ; Else, terminate (implicit) 
```
[Answer]
## Groovy, 51 bytes
```
{a,b,c,d->while(Eval.me("$a$b$c")){println a;a+=d}}
```
This is an unnamed closure. [Try it Online!](https://tio.run/#v3N5j)
**Caution** - If you want to test this with `groovy console`, make sure you kill the entire process when the input causes an infinite loop. I noticed this after it consumed ~5 gigs of RAM.
[Answer]
## [QBIC](https://drive.google.com/drive/folders/0B0R1Jgqp8Gg4cVJCZkRkdEthZDQ), ~~51~~ 40 bytes
```
:;::{?a┘a=a+c~A=@<`|~a>=b|_X]\~a<=b|_X
```
And three minutes after posting I realised I could simplify the terminator logic...
```
:;::      Consecutively read a, A$, b and c from the command line
{?a┘      Start an infinite loop; print a, add a newline to the source
a=a+c     increment a
~A=@<`|   If we are in LESS THAN mode
  ~a>=b   and IF we are no longer LESS
    |_X]  THEN QUIT, end if.
  \       ELSE (we're in GREATER THAN mode)
    ~a<=b IF we are no longer GREATER
    |_X   THEN QUIT
          The last IF and the loop are auto-closed
```
[Answer]
## Batch, 94 bytes
```
@set i=%1
@set o=gtr
@if "%~2"=="<" set o=lss
:g
@if %i% %o% %3 echo %i%&set/ai+=%4&goto g
```
If it wasn't for the second parameter behaviour, it could be done in 53 bytes:
```
@for /l %%i in (%1,%4,%n%)do @if not %%i==%3 echo %%i
```
This simply does nothing if the step has the wrong sign. The extra test is because Batch's `for` loop allows the loop variable to equal the end value.
[Answer]
## Clojure, 66 bytes
```
#(loop[i %](if(({">">"<"<}%2)i %3)(do(println i)(recur(+ i %4)))))
```
This could have been 55 bytes as`<` and `>` are functions in Clojure:
```
(def f #(loop[i %](if(%2 i %3)(do(println i)(recur(+ i %4))))))
(f 1 < 10 1)
```
[Answer]
# TI-Basic, ~~41~~ 34 bytes
```
Prompt A,Str2,Str3,D
While expr("A"+Str2+Str3
Disp A
A+D->A
End
```
]