Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Output some reserved words

For a computer language, a reserved word is a word that cannot be used as an identifier, such as the name of a variable, function, or label. For other computer languages, keywords can be considered as the set of the language instructions.

Challenge

Using your language of choice, write a code in the chosen language that given a number between one and ten, 1<=n<=10, outputs any n reserved words (keywords) of the chosen language.

Specifics

  • If the chosen language is case sensitive the outputted keywords must be also.
  • If the chosen language is not case sensitive the outputted keywords can be in any case.
  • If the chosen language has less than 10 keywords saying p, the code must output all the reserved words for any n between p and 10.
  • If possible specify in the answer whether you consider operators as keywords or not.

Possible samples for Java (JDK10)

  • n=1 --> true
  • n=3 --> try new interface
  • n=4 --> continue this long break

Possible samples for ><>

  • n=1 --> >
  • n=3 --> > < ^
  • n=4 --> > < \ /

Possible samples for Brain-Flak

  • n=1 --> (
  • n=3 --> ( ) [ ]
  • n=9 --> ( ) [ ] { } < >

Rules

  • The input and output can be given in any convenient format.
  • No need to handle invalid input values, valid inputs are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
  • Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
  • If possible, please include a link to an on-line testing environment so other people can try out your code!
  • Standard loopholes are forbidden.
  • This is so all usual golfing rules apply, and the shortest code (in bytes) wins.

Answer*

Draft saved
Draft discarded
Cancel
6
  • \$\begingroup\$ n=>'|/^%+<&*-='.substr(-n) \$\endgroup\$ Commented Apr 16, 2018 at 11:45
  • \$\begingroup\$ Oh yeah , Lol still golfing. Thanks @Adám. Appreciate it. \$\endgroup\$ Commented Apr 16, 2018 at 11:46
  • 3
    \$\begingroup\$ I don't think int is a "reserved word" as per the definition in the challenge. You can certainly name a variable int in JavaScript. \$\endgroup\$ Commented Apr 16, 2018 at 22:54
  • 1
    \$\begingroup\$ If I remember well, int is reserved as a possible future keyword by the ECMAScript specification. \$\endgroup\$ Commented Apr 17, 2018 at 12:36
  • \$\begingroup\$ Why substr instead of slice? \$\endgroup\$ Commented Apr 17, 2018 at 16:21

AltStyle によって変換されたページ (->オリジナル) /