- Prolog - Discussion
- Prolog - Useful Resources
- Prolog - Quick Guide
- Monkey and Banana Problem
- Prolog - Linked Lists
- Towers of Hanoi Problem
- Prolog - Examples of Cuts
- Prolog - Basic Programs
- Tree Data Structure (Case Study)
- Prolog - Built-In Predicates
- Prolog - Inputs and Outputs
- Prolog - Different and Not
- Prolog - Backtracking
- Recursion and Structures
- Prolog - Lists
- Conjunctions & Disjunctions
- Loop & Decision Making
- Prolog - Operators
- Prolog - Data Objects
- Prolog - Relations
- Prolog - Basics
- Prolog - Hello World
- Prolog - Environment Setup
- Prolog - Introduction
- Prolog - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Prolog - Hello World
In the previous section, we have seen how to install GNU Prolog. Now, we will see how to write a simple Hello World program in our Prolog environment.
Hello World Program
After running the GNU prolog, we can write hello world program directly from the console. To do so, we have to write the command as follows −
write( Hello World ).
Note − After each pne, you have to use one period (.) symbol to show that the pne has ended.
The corresponding output will be as shown below −
![Hello World](/prolog/images/hello_world.jpg)
Now let us see how to run the Prolog script file (extension is *.pl) into the Prolog console.
Before running *.pl file, we must store the file into the directory where the GNU prolog console is pointing, otherwise just change the directory by the following steps −
Step 1 − From the prolog console, go to File > Change Dir, then cpck on that menu.
Step 2 − Select the proper folder and press OK.
![Select Working Directory](/prolog/images/select_working_directory.jpg)
Now we can see in the prolog console, it shows that we have successfully changed the directory.
![prolog_console](/prolog/images/prolog_console.jpg)
Step 3 − Now create one file (extension is *.pl) and write the code as follows −
main :- write( This is sample Prolog program ), write( This program is written into hello_world.pl file ).
Now let’s run the code. To run it, we have to write the file name as follows −
[hello_world]
The output is as follows −
![prolog_console1](/prolog/images/prolog_console1.jpg)